package com.gxgy.web.controller;

import com.gxgy.common.annotation.Log;
import com.gxgy.common.core.controller.BaseController;
import com.gxgy.common.core.domain.R;
import com.gxgy.common.enums.BusinessType;
import com.gxgy.common.utils.poi.ExcelUtil;
import com.gxgy.web.domain.TUser;
import com.gxgy.web.service.ITUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 小程序用户Controller
 *
 * @author mobin
 * @date 2024-11-08
 */
@Api(tags = "小程序用户")
@RestController
@RequestMapping("/web/appuser")
public class TUserController extends BaseController {
    @Autowired
    private ITUserService tUserService;

    /**
     * 查询小程序用户列表
     */
    @ApiOperation("查询小程序用户列表")
    @PreAuthorize("@ss.hasPermi('web:appuser:list')")
    @GetMapping("/list")
    public R<List<TUser>> list(TUser tUser) {
        startPage();
        List<TUser> list = tUserService.selectTUserList(tUser);
        return R.ok(list);
    }

    /**
     * 导出小程序用户列表
     */
    @ApiOperation("导出小程序用户列表")
    @PreAuthorize("@ss.hasPermi('web:appuser:export')")
    @Log(title = "小程序用户" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TUser tUser) {
        List<TUser> list = tUserService.selectTUserList(tUser);
        ExcelUtil<TUser> util = new ExcelUtil<TUser>(TUser.class);
        util.exportExcel(response, list, "小程序用户数据");
    }

    /**
     * 获取小程序用户详细信息
     */
    @ApiOperation("获取小程序用户详细信息")
    @PreAuthorize("@ss.hasPermi('web:appuser:query')")
    @GetMapping(value = "/{id}")
    public R<Object> getInfo(@PathVariable("id") Long id) {
        return R.ok(tUserService.selectTUserById(id));
    }

    /**
     * 新增小程序用户
     */
    @ApiOperation("新增小程序用户")
    @PreAuthorize("@ss.hasPermi('web:appuser:add')")
    @Log(title = "小程序用户" , businessType = BusinessType.INSERT)
    @PostMapping
    public R<Object> add(@RequestBody TUser tUser) {
        tUser.setCreateBy(getUsername());
        return R.ok(tUserService.insertTUser(tUser));
    }

    /**
     * 修改小程序用户
     */
    @ApiOperation("修改小程序用户")
    @PreAuthorize("@ss.hasPermi('web:appuser:edit')")
    @Log(title = "小程序用户" , businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Object> edit(@RequestBody TUser tUser) {
        return R.ok(tUserService.updateTUser(tUser));
    }

    /**
     * 删除小程序用户
     */
    @ApiOperation("删除小程序用户")
    @PreAuthorize("@ss.hasPermi('web:appuser:remove')")
    @Log(title = "小程序用户" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Object> remove(@PathVariable Long[] ids) {
        return R.ok(tUserService.deleteTUserByIds(ids));
    }
}
